/**
 * Created by Freeman on 2018/1/20.
 */
import {normalize, schema} from 'normalizr';
import {ADD_ENTITIES} from "../../constants/ActionTypes";

export function normalizeResult(entity: schema.Entity, result: Object) {
  return async (dispatch: Function) => {
    const normalizedResult = normalize(result, entity);

    dispatch({
      type: ADD_ENTITIES,
      ...normalizedResult,
    });
  };
}
